package com.blog.blog.controller;

import com.blog.sys.controller.SysUserController;
import com.blog.common.newclass.Result;
import com.blog.common.newclass.StrSource;
import com.blog.common.newclass.dostringabs.DoEntryShiroMd5;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CommonController {
    private final static Logger logger = LoggerFactory.getLogger(SysUserController.class);

    /**
     * 返回结果key
     */
    public final static String RES = "res";

    /**
     * md5加密密码
     * @param password
     * @return
     */
    public static String md5EntryPassword(String password) throws Exception {
        return new DoEntryShiroMd5(new StrSource(password)).getStr();
    }

    /**
     * 获得sql错误信息
     * @param e
     * @return
     */
    public static String sqlErrMsg(RuntimeException e) {
        return e.getCause().getCause().getLocalizedMessage();
    }


    /**
     * 返回出错
     * @param errMsg
     * @return
     */
    public Result error(String errMsg){
        return new Result(false, null, null, errMsg, 1, 0);
    }


    /**
     * 返回成功
     * @param msg
     * @return
     */
    public Result success(String msg, Object data){
        return new Result(true, msg, data, null, 0, 0);
    }

    /**
     * 返回警告
     * @param msg
     * @return
     */
    public Result warn(String msg){
        return new Result(true, msg, null, null, 2, 0);
    }

    /**
     * 返回成功
     * @return
     */
    public Result page(Object data, long count){
        return new Result(true, null, data, null, 0, count);
    }

}


